package com.lanxin.oa.fiancial.service;
import java.util.*;

import com.lanxin.oa.fiancial.dao.BxInformalTjDao;
import com.lanxin.util.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BxInformalTjServiceImpl implements BxInformalTjService {
	@Autowired
	private BxInformalTjDao bxInformalTjDao;



	@Override
	public List typetj(Date startDate, Date endDate, String tjtype) {
		if(tjtype!=null){
			if (tjtype.equals("1")) {// 按部门统计

				return bxInformalTjDao.selectdepttj(startDate, endDate);

			}
			if (tjtype.equals("2")) {// 按类型统计
				return bxInformalTjDao.selecttypetj(startDate, endDate);
			}
		}
		return null;
	}

	@Override
	public Map<String, Object> tablezhu(Date startDate, Date endDate, String tjtype) {
		List list = new ArrayList();
		Map<String, Object> map = new HashMap<String, Object>();

		if (tjtype.equals("1")||tjtype.equals("")) {// 按部门统计
			list = bxInformalTjDao.selectdepttj(startDate, endDate);
			
			if(list==null || list.size()==0) {
				return null;
			}
			
			List<String> list1 = new ArrayList<String>();
			List<Double> list2 = new ArrayList<Double>();
			for (int i = 0; i < list.size(); i++) {
				Object[] o = (Object[]) list.get(i);
				
				if(o[1]==null) {
					o[1]=0;
				}
				list1.add(o[0].toString());
				list2.add(Double.valueOf(o[1].toString()));

			}
			map.put("key", list1);
			map.put("value", list2);

		}
		if (tjtype.equals("2")) {// 按类型统计
			list = bxInformalTjDao.selecttypetj(startDate, endDate);
			List<String> list1 = new ArrayList<String>();
			List<Double> list2 = new ArrayList<Double>();
			for (int i = 0; i < list.size(); i++) {
				Object[] o = (Object[]) list.get(i);
				list1.add(o[0].toString());
				
				if(o[1]==null) {
					o[1]=0;
				}
				list2.add(Double.valueOf(o[1].toString()));

			}
			map.put("key", list1);
			map.put("value", list2);

		}
		return map;
	}

	@Override
	public List tablebing(Date startDate, Date endDate, String tjtype) {
		List list = new ArrayList();
		List<PieVo> lisPieVos = new ArrayList<PieVo>();
		
		if (tjtype.equals("1")||tjtype.equals("")) {// 按部门统计
			list = bxInformalTjDao.selectdepttj(startDate, endDate);
	
			for (int i = 0; i < list.size(); i++) {
				Object[] o = (Object[]) list.get(i);
				
				if(o[1]==null) {
					o[1]=0;
				}
				PieVo pieVo = new PieVo(o[0].toString(), Double.valueOf(o[1].toString()));
				lisPieVos.add(pieVo);
			}
		}
		if (tjtype .equals("2")) {// 按类型统计
			
			list = bxInformalTjDao.selecttypetj(startDate, endDate);
			for (int i = 0; i < list.size(); i++) {
				Object[] o = (Object[]) list.get(i);
				
				if(o[1]==null) {
					o[1]=0;
				}
				PieVo pieVo = new PieVo(o[0].toString(), Double.valueOf(o[1].toString()));
				lisPieVos.add(pieVo);
			}
		}
		return lisPieVos;

	}

}
